package com.bart.scala.ch11


/**
 * 为类 添加隐式方法
 */

class Person(name: String) {
  override def toString: String = ">>>"+ name
}

class RichPerson(p : Person) {
  def say(s:String) = println(f"RichPerson [$p] say : [$s]")
}


object MainApp2 extends App {
  implicit def person2RichPerson(p: Person) = new RichPerson(p)

  val p = new Person("jack")
  p.say("hello!") // person是没这个方法的，函数person2RichPerson修改为RichPerson
 // RichPerson [>>>jack] say : [hello!]
}
